// import orderstate from 'store/order/state'
export default {
  add_adress (state, content) {
    content.id = Date.now()
    const indexs = state.address.findIndex(address => address.isDefault)
    if (!state.address.length || !content.isDefault) {
      state.address.push(content)
    } else {
      if (indexs !== -1) {
        state.address[indexs].isDefault = false
      }
      state.address.push(content)
    }
  },
  update_Address (state, { content, index }) {
    if (content.isDefault) { // 如果将修改的地址是默认联系人
      // 修改默认联系人 遍历原先的使得默认选项为空
      const defaultIndex = state.address.findIndex(address => address.isDefault)
      if (defaultIndex !== -1) {
        state.address[defaultIndex].isDefault = false
      }
    }
    state.address[index] = content
  },
  delet_Address (state, index) {
    // const test = orderstate.order.currentOrder.contact.find(contact => state.address[index] === contact)
    // if (test) {
    //   orderstate.order.currentOrder.contact = state.address[0]
    // }
    state.address.splice(index, 1)
  }
}
